package dazuoye.基于事件的隐式调用;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class Test implements Listenable{
    private Listener listener;
    @Override
    public void addListener(Listener listener) {
        this.listener=listener;
    }

    @Override
    public void triggerListener(Event e) {
        this.listener.onEvent(e);
    }
    public void inputOperation(String url,int i) throws Exception {
        File file= new File(url);
        BufferedReader input= new BufferedReader(new FileReader(file));
        String s;
        List<String> list=new ArrayList<>();
        while((s=input.readLine())!=null)
        {
            list.add(s);
        }
        this.triggerListener(new KwicEvent(i,list));
    }

    public static void main(String[] args) throws Exception {
        Test t=new Test();
        t.addListener(new KwicListener());
        t.inputOperation("C:\\Users\\topto\\Desktop\\新建 Text Document.txt",0);
    }
}
